import 'package:flutter_text_reader/flutter_text_reader_widget_controller.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';

import 'FlutterTextReaderWidgetController.dart';

typedef TOnFlutterTextReaderCreated = void Function(FlutterTextReaderWidgetController controller);


class FlutterTextReaderWidget extends StatefulWidget {
  FlutterTextReaderWidget({super.key, required this.onCreated});

  FlutterTextReaderWidgetController onCreated;

  @override
  State<StatefulWidget> createState() {
    return _FlutterTextReaderWidgetWidgetState();
  }
}

class _FlutterTextReaderWidgetWidgetState extends State<FlutterTextReaderWidget> {
  _FlutterTextReaderWidgetWidgetState();
  FlutterTextReaderWidgetController? controller;

  @override
  void initState() {
    super.initState();


  }
  @override
  Widget build(BuildContext context) {
    return AndroidView(
          viewType: "com.maiyuren.sudict/fluttertextreader",
          onPlatformViewCreated: (viewId) {
            controller = FlutterTextReaderWidgetController(id: viewId);
            widget.onCreated(controller!);
          },
        );
  }

  @override
  void dispose() {
    controller?.dispose();
    super.dispose();
  }
}
